/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ez2find.manager;

import com.ez2find.model.Message;
import com.ez2find.model.Nick;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author org.@le
 */
@Stateless
public class SearchBean implements SearchLocal {

    @PersistenceContext
    private EntityManager em;

    public List<Message> search(String words) {
        return em.createQuery("SELECT m FROM Message m WHERE m.content LIKE '%" + words + "%'").getResultList();
    }
    
    public Nick searchHandle(String words){
        if (!em.createQuery("SELECT m FROM Nick m WHERE m.name LIKE '" + words + "'").getResultList().isEmpty())
        {return (Nick) em.createQuery("SELECT m FROM Nick m WHERE m.name LIKE '" + words + "'").getResultList().get(0);}
        else{
            return null;
        }
    }
}
